package com.wxy.ej.flow.utils;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class Test1 {

    public static void main(String[] args) throws ScriptException {
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("javascript");


        /*Map<String,Object> param = new HashMap<String,Object>();
        param.put("page", 0);
        engine.put("a", param);
        */

        Map<String,Object> data = new HashMap();
        data.put("a", 11);
        engine.put("data", data);

        engine.put("num", 22);

        engine.eval("data.a = num*2; data.b = data.a+'';");
        engine.eval("data.c = parseInt(data.b,10);");
        engine.eval("data.d = parseInt(data.a,10);");
        engine.eval("data.d1 = data.a.intValue();");
        engine.eval("data.e = num;");
        engine.eval("data.f = parseInt('33',10);");
        System.out.println(data);

        //System.out.println(engine.eval("print(num*3)"));
        //System.out.println(engine.eval("print(parseInt(num)+2)"));

        /*System.out.println(o instanceof Number);
        System.out.println(o instanceof Double);
        System.out.println(o instanceof Float);
        System.out.println(o instanceof Integer);
        System.out.println(o instanceof String);
        System.out.println(o instanceof Serializable);
        System.out.println(o.toString());*/

        /*if (o instanceof Double) {
            double d = (double)o;
            System.out.println(d);
            int i = (int)d;
            System.out.println(i);
            System.out.println(d==i);
        }
        Integer o1 = (new BigDecimal(o.toString())).intValue();
        System.out.println(o1);*/
    }
}
